package org.deplyclient;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Command {

	public static void main(String[] command) {
		try {  
            String[] cmd = new String[] { "/bin/sh", "-c", "ps -ef | grep z6pineureka-0.0.1" };  
            Process ps = Runtime.getRuntime().exec(cmd);  
  
            BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream()));  
            StringBuffer sb = new StringBuffer();  
            String line;  
            while ((line = br.readLine()) != null) {  
                sb.append(line).append("\n");  
                if(line.indexOf("java")>0) {
                		String[] dataItems =  line.split("  ");
                		
                		System.out.println(dataItems[0]+","+dataItems[1]+","+dataItems[2]);
                		System.out.println(command.length);
                		if(command.length!=0&&"kill".equals(command[0])) {
                			String[] cmdItem = new String[] { "/bin/sh", "-c", "kill -9 "+dataItems[2] }; 
                			Runtime.getRuntime().exec(cmdItem); 
                		}
                }
            }  
            String result = sb.toString();  
  
            //System.out.println(result);  
  
            //cmd = new String[] { "/bin/sh", "-c", "kill -9 3926" }; 
            //Runtime.getRuntime().exec(cmd); 
            
        } catch (Exception e) {  
        		System.out.println("----error-----");  
            e.printStackTrace();  
        } 
	}
}
